module Facility;

import DND;

import S306;
import DefVar;
import DefOrder;
import World;
import Database;
import FacilityLocation;

Facility::Facility(const SL& sl) :
	_sl(sl)
{
	if (_sl._type == FacilityLocation::GetClassID())
	{
		_data = new FacilityLocation(this);
	}
}


void Facility::RefreshUI()
{
	if (FacilityLocation* location = _data.Cast<FacilityLocation>())
	{
		location->RefreshUI();
	}
}



void Facility::Render(real scale_level)
{
	Vector2 pos = g_world->Xy2WindowCenter(_sl._xy);

	if (FacilityLocation* location = _data.Cast<FacilityLocation>())
	{
		location->Render(pos, scale_level);
	}
}


bool Facility::IsPickup()
{
	if (FacilityLocation* location = _data.Cast<FacilityLocation>())
	{
		return location->IsPickup();
	}
	return false;
}


Facility::Facility(StreamInput& s, natural version)
{
	s.Read(&_sl);
	if (_sl._type == FacilityLocation::GetClassID())
	{
		FacilityLocation* location = new FacilityLocation(this, s);
		_data = location;
	}
}


void Facility::Save(StreamOutput& s)
{
	s.Write(&_sl);
	if (FacilityLocation* location = _data.Cast<FacilityLocation>())
	{
		location->Save(s);
	}
}



Facility::~Facility()
{
	if (FacilityLocation* location = _data.Cast<FacilityLocation>())
	{
		delete location;
	}
}
